# -*- coding: utf-8 -*-
import os
from ConfigParser import ConfigParser

#TODO: Windows are not supported yet

# name and version
PROGRAM_NAME = "TwiCage"
PROGRAM_VERSION = "0.4"

# path to gui 
GLADE_DIR = os.path.abspath('gui')

# get the home dir our app
HOME_DIR = os.environ['HOME'] + "/.twicage/"
CACHE_DIR = "%scache/" % HOME_DIR
PREFS_DIR = "%sprefs/" % HOME_DIR
CONF_FILE = "%sconfig" % PREFS_DIR

# create dirs for conf if not created yet
def create_dir(dir_name):
    if not os.path.isdir(dir_name):
        os.mkdir(dir_name)
        print "Create dir %s" % dir_name

# create home for app
def create_home_dir():
    create_dir(HOME_DIR)
    create_dir(CACHE_DIR)
    create_dir(PREFS_DIR)
    
# create and configure conf files
def create_conf_file():
    if not os.path.isfile(CONF_FILE):
        config = ConfigParser()
        config.add_section("login")
        config.set("login","userlogin","")
        config.set("login","password","")
        config.add_section("window_pos")        
        config.set("window_pos","x","100")
        config.set("window_pos","y","100")
        config.add_section("geral")
        config.set("geral","list_size","0")
        config.write(file(CONF_FILE,"w"))
        os.chmod(CONF_FILE,0600)
        print "Create file %s" % CONF_FILE

# get the config object
def get_config():
    config = ConfigParser()
    config.read(CONF_FILE)
    return config

# set the configuration (commit conf)
def set_config(config):
    fp = file(CONF_FILE,"w")
    config.write(fp)
    return config
